package com.bh.web.controller.kysys;

import com.bh.common.annotation.Log;
import com.bh.common.core.controller.BaseController;
import com.bh.common.core.domain.AjaxResult;
import com.bh.common.enums.BusinessType;
import com.bh.common.utils.poi.ExcelUtil;
import com.bh.kysys.domain.JcSysOrganization;
import com.bh.kysys.service.IJcSysOrganizationService;
import com.bh.kysys.vo.JcSysOrganizationVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 网点机构Controller
 * 
 * @author slx
 * @date 2023-11-12
 */
@RestController
@RequestMapping("/kysys/sysOrganization")
public class JcSysOrganizationController extends BaseController
{
    @Autowired
    private IJcSysOrganizationService jcSysOrganizationService;

    /**
     * 查询网点机构列表
     */
    @ApiOperation("查询网点机构列表")
    @PreAuthorize("@ss.hasPermi('kysys:sysOrganization:list')")
    @GetMapping("/list")
    public AjaxResult list(JcSysOrganization jcSysOrganization)
    {
        List<JcSysOrganization> list = jcSysOrganizationService.selectJcSysOrganizationList(jcSysOrganization);
        return success(list);
    }

    /**
     * 导出网点机构列表
     */
    @PreAuthorize("@ss.hasPermi('kysys:sysOrganization:export')")
    @Log(title = "网点机构", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JcSysOrganization jcSysOrganization)
    {
        List<JcSysOrganization> list = jcSysOrganizationService.selectJcSysOrganizationList(jcSysOrganization);
        ExcelUtil<JcSysOrganization> util = new ExcelUtil<JcSysOrganization>(JcSysOrganization.class);
        util.exportExcel(response, list, "网点机构数据");
    }


    /**
     * 用于获取组织机构下拉列表通用方法
     *
     * @return
     */
    @GetMapping("/getOrgTree")
    public AjaxResult getOrgTree(JcSysOrganizationVo jcSysOrganization) {
        List<JcSysOrganization> list = jcSysOrganizationService.selectJcSysOrganizationTree(jcSysOrganization);
        return list != null ? success(list) : error();
    }


    /**
     * 查询网点机构列表
     */
    @ApiOperation("查询目的地网点机构列表")
    @GetMapping("/getTargetOrg")
    public AjaxResult getTargetOrg(JcSysOrganizationVo jcSysOrganization)
    {
        List<JcSysOrganization> list = jcSysOrganizationService.selectTargetJcSysOrganizationList(jcSysOrganization);
        return success(list);
    }

    /**
     * 获取网点机构详细信息
     */
    @ApiOperation("获取网点机构详细信息")
    @PreAuthorize("@ss.hasPermi('kysys:sysOrganization:query')")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(jcSysOrganizationService.selectJcSysOrganizationById(id));
    }

    /**
     * 新增网点机构
     */
    @ApiOperation("新增网点机构")
    @PreAuthorize("@ss.hasPermi('kysys:sysOrganization:add')")
    @Log(title = "网点机构", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JcSysOrganization jcSysOrganization)
    {
        return toAjax(jcSysOrganizationService.insertJcSysOrganization(jcSysOrganization));
    }

    /**
     * 修改网点机构
     */
    @ApiOperation("修改网点机构")
    @PreAuthorize("@ss.hasPermi('kysys:sysOrganization:edit')")
    @Log(title = "网点机构", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JcSysOrganization jcSysOrganization)
    {
        return toAjax(jcSysOrganizationService.updateJcSysOrganization(jcSysOrganization));
    }

    /**
     * 删除网点机构
     */
    @ApiOperation("删除网点机构")
    @PreAuthorize("@ss.hasPermi('kysys:sysOrganization:remove')")
    @Log(title = "网点机构", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(jcSysOrganizationService.deleteJcSysOrganizationByIds(ids));
    }
}
